<template>
    <div>
        <h1 class="Title">Remark List</h1>
        <input type="text" class="txt" v-model="observer" placeholder="输入用户名进行搜索">
        <button @click="searchPosts(observer)" class="btn3">SEARCH</button>
        <table class="blog-table">
            <thead>
            <tr>
                <th>User</th>
                <th>Content</th>
                <th>Date</th>
              <th></th>
            </tr>
            </thead>
            <tbody>
            <tr v-for="remark in remarks" :key="remark.id" >
                <td>
                    <div style="height: 50px;width: 100px; overflow: hidden;">
                        <div style="height: 50px;width: 200px; overflow: hidden;">{{ remark.observer }}</div>
                    </div>
                </td>
                <td>
                    <div style="height: 50px;width: 200px; overflow: hidden;">{{ remark.content }}</div>
                </td>
                <td>
                    <div style="height: 50px;width: 200px; overflow: hidden;">{{ remark.createDate}}</div>
                </td>
                <td>
                    <button @click="deleteRemark(remark.id)" class="btn3">删除</button>
                </td>
            </tr>
            </tbody>

        </table>
    </div>
</template>

<script>
import axios from 'axios';

export default {
    data() {
        return {
            remarks: [],
            observer: ''
        };
    },
    mounted() {
        this.getRemarksData();
    },
    methods: {
        getRemarksData() {
            axios.get('/api//remarkAll')
                .then(response => {
                    this. remarks = response.data.data;
                })
                .catch(error => {
                    console.error(error);
                });
        },
        searchPosts(observer) {
            axios.get(`/api/remarks?observer=${observer}`)
                .then(response => {
                    if (response.data === null) {
                        alert("查询无结果");
                    } else {
                        this.remarks = response.data;
                    }
                })
                .catch(error => {
                    console.error(error);
                });
        },
        deleteRemark(id) {
            const r = confirm("确定要删除吗？");
            if (r==true){
                axios.delete(`/api/remark/${id}`)
                    .then(response => {
                        this.getRemarksData();
                    })
                    .catch(error => {
                        console.error(error);
                    });
            }
            else{
                return
            }
        },
    },
};
</script>

<style>
.Title{
  color: #cccccc;
}
.scrollbar-demo-item {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 50px;
    margin: 10px;
    text-align: center;
    border-radius: 4px;
    background: var(--el-color-primary-light-9);
    color: var(--el-color-primary);
}
.txt{
  width: 215px;
  height: 25px;
  outline: none;
  border:0;
  border-radius: 5px;
  background:#d1d2d4;

}
.btn3{
  width:65px;
  height: 35px;
  background:radial-gradient(ellipse at center,#73f219,#d1d2d4,#000000);
  border-radius: 5px;
}
.btn3:hover{
  cursor: pointer;
  background: radial-gradient(ellipse at center,#d1d2d4,#73f219,#000000);
}


.blog-table {
  width: 100%;
  border-collapse:separate;
  border-spacing:4px;
}

.blog-table td {
  padding: 12px;
  text-align:left;
  border:0;
  border-bottom: 1px solid #fff;
  border-radius: 4px;
}

.blog-table th {
  padding: 12px;
  text-align: center;
  border:0;
  border-bottom: 1px solid #fff;
  border-radius: 4px;
  background:linear-gradient(90deg, #d1d2d4,#73f219,#000000);
  color-image:#fff;
  font-family: Papyrus;
}

.blog-table tbody tr:hover {
  background-color: #fff;
}
</style>
